package com.vsd.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.demo.domain.Focus;
import com.demo.util.SqlUtils;
import com.vsd.repository.FocusRepository;
import com.vsd.service.FocusService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 用户服务接口实现
 * 
 * @author jiekechoo
 *
 */
@Service
@Transactional
public class FocusServiceImpl implements FocusService {
	@SuppressWarnings("unused")
	private static final Logger LOGGER = LoggerFactory
			.getLogger(FocusServiceImpl.class);
	
	@Autowired
	JdbcTemplate jdbcTemplate;
	@Autowired
	FocusRepository focusRepository;

	@Override
	public Page<Focus> findByLocationAndRestraint(Integer location,
			String restraint, Pageable p) {
		return focusRepository.findByLocationAndRestraint(location, restraint, p);
	}

	@Override
	public Page<Focus> findByLocation(Integer location, Pageable p) {
		return focusRepository.findByLocation(location, p);
	}

	@Override
	public Page<Focus> findAll(Pageable p) {
		return focusRepository.findAll(p);
	}

	@Override
	public void save(Focus f) {
		focusRepository.save(f);
	}

	@Override
	public void delById(String id) {
		focusRepository.delete(id);
	}

	@Override
	public int updateByPrimaryKeySelective(Focus f) {
		try {
			String sql = SqlUtils.update(f, true, " where id = '"+f.getId()+"'");
			return jdbcTemplate.update(sql);
		}catch (Exception e) {
			return 0;
		}
	}

	@Override
	public Focus findOne(String id) {
		return focusRepository.findOne(id);
	}


	@Override
	public Page<Focus> findLocationAndAreaCode(Integer location,String areaCode, Pageable p) {
		// TODO Auto-generated method stub
		return focusRepository.findByLocationAndRestraint(location, areaCode, p);
	}
	
	
}
